﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>JS Loops Exercise 4</title>
    <link href="styles/js-console.css" rel="stylesheet" />
</head>
<body>
    <h1>Finds the lexicographically smallest and largest property in document, window and navigator objects</h1>
    <div id="js-console"></div>
    <script src="scripts/js-console.js"></script>
    <script>
        var min = "";
        var firstMin = true;
        var max = "";
        var firstMax = true;

        for (var property in document)
        {
            if (false != firstMin)
            {
                min = property.toString();
                firstMin = false;
            }
            else if (property.toString().localeCompare(min, 0) < 0)
            {
                min = property.toString();
            }
            if (false != firstMax)
            {
                max = property.toString();
                firstMax = false;
            }
            else if (property.toString().localeCompare(max, 0) > 0)
            {
                max = property.toString();
            }
            
            jsConsole.writeLine("document[" + property + "] min: " + min + " max: " + max);
        }

        for (var property in window)
        {
            if (property.toString().localeCompare(min, 0) < 0)
            {
                min = property.toString();
            }
            if (property.toString().localeCompare(max, 0) > 0)
            {
                max = property.toString();
            }

            jsConsole.writeLine("window[" + property + "] min: " + min + " max: " + max);
        }

        for (var property in navigator)
        {
            if (property.toString().localeCompare(min, 0) < 0)
            {
                min = property.toString();
            }
            if (property.toString().localeCompare(max, 0) > 0)
            {
                max = property.toString();
            }

            jsConsole.writeLine("navigator[" + property + "] min: " + min + " max: " + max);
        }

        jsConsole.writeLine("FINAL min: " + min + " max: " + max);
                
    </script>
</body>
</html>
